<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

use App\Http\Requests;
use App\Models\System\User;
use App\Notifications\ResetCustomerPassword;
use Carbon\Carbon;
use Illuminate\Notifications\Notifiable;


class UserController extends Controller
{
    use Notifiable;
    private $email;

    public function register(Request $request)
    {
        User::create([
            'email' => $request->email,
            'password' => bcrypt($request->password),
            'remember_token' => str_random(60)
        ]);
    }

    function login(Request $request)
    {
        $email = $request->email;
        $user = User::where('email', $email)->first();

        if (!$user) {
            return ['status' => 0, 'msg' => '用户不存在'];
        }

        if (!\Hash::check($request->password, $user->password)) {
            return ['status' => 0, 'msg' => '密码错误'];
        }

        return ['status' => 1, 'msg' => $user];
    }
}